package com.ima;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.dev.CheckableItem;
import com.dev.DefaultPage;
import com.dev.GUI;
import com.dev.IconViewClose;
import com.dev.MainActivity;

public class MoreSettingForIMP extends LinearLayout implements OnClickListener {
	WindowManager.LayoutParams wlp=new WindowManager.LayoutParams();
	LinearLayout titlebar;
	LayoutParams titlebarlp;
	TextView title;
	IconViewClose close;
	MainActivity ma;
	CheckableItem itAutoFillScreen;
	DefaultPage.TransverseItem itGuideColor;
	DefaultPage.TransverseItem itCrossGuideColor;
	final static String imgFillScreen="imp_img_auto_fill_screen";
	final static String guideColor="imp_guide_color";
	final static String crossGuideColor="imp_cross_guide_color";
	MoreSettingForIMP(MainActivity ma){
		super(ma);
		this.ma=ma;
		setOrientation(VERTICAL);
		setBackground(new GUI.BorderDrawable());
		title=new TextView(ma);
		title.setGravity(Gravity.CENTER_VERTICAL);
		int textSize=(int)(13*ma.dp);
		int padding=10;
		close=new IconViewClose(ma);
		close.setOnClickListener(this);
		title.getPaint().setTextSize(textSize);
		title.setPadding(padding,0,0,0);
		titlebar=new LinearLayout(ma);
		titlebar.setOrientation(HORIZONTAL);
		titlebar.addView(title,new LayoutParams(0,-1,1f));
		titlebar.addView(close);
		titlebarlp=new LayoutParams(-1,ma.dialogTitleBarHeight);
		itAutoFillScreen=new CheckableItem(ma,"页面打开时图像自动适应全屏");
		itAutoFillScreen.setOnClickListener(this);
		itGuideColor=new DefaultPage.TransverseItem(ma);
		itGuideColor.setOnClickListener(this);
		itCrossGuideColor=new DefaultPage.TransverseItem(ma);
		itCrossGuideColor.setOnClickListener(this);
		LayoutParams rowlp=new LayoutParams(-1,(int)(29*ma.dp));
		addView(titlebar,titlebarlp);
		addView(itAutoFillScreen,rowlp);
		addView(itGuideColor,rowlp);
		addView(itCrossGuideColor,rowlp);
	}
	void show(){
		itAutoFillScreen.setSelected(ma.shr.getBoolean(imgFillScreen,true));
		itGuideColor.setText("辅助线默认颜色：#"+String.format("%08x",ma.shr.getInt(guideColor,0xff000000)));
		itCrossGuideColor.setText("十字辅助线默认颜色：#"+String.format("%08x",ma.shr.getInt(crossGuideColor,0xffff0000)));
		wlp.width=ma.wp*4/5;
		wlp.height=-2;
		ma.wm.addView(this,wlp);
	}
	@Override
	public void onClick(View view) {
		if(view==close){//onClick
			ma.wm.removeView(this);
		}else if(view==itAutoFillScreen){//onClick
			if(itAutoFillScreen.isSelected()){
				itAutoFillScreen.setSelected(false);
				ma.shr.edit().putBoolean(imgFillScreen,false).apply();
			}else{
				itAutoFillScreen.setSelected(true);
				ma.shr.edit().putBoolean(imgFillScreen,true).apply();
			}
		}else if(view==itGuideColor){//onClick

		}else if(view==itCrossGuideColor){//onClick

		}
	}
}
